In this chapter we continue our study of classes and
data abstraction. We discuss many more advanced
topics and lay the groundwork for the discussion of
classes and operator overloading in Chapter 8. The
discussion in Chapters 6 through 8 encourages
programmers to use objects, what we call <i>object-based
programming (OBP)</i>. Then, Chapters 9 and 10
introduce inheritance and polymorphism--the
techniques of truly <i>object-oriented programming
(OOP)</i>. In this and several subsequent chapters, we use
the C-style strings we introduced in Chapter 5. This will <br>
</page>
<page>
help the reader master the complex topic of C pointers
and prepare for the professional world in which the
reader will see a great deal of C legacy code that has
been put in place over the last two decades. In Chapter
19, "Class <b>string</b>," we discuss the new style of strings,
namely strings as full-fledged class objects. Thus, the
reader will become familiar with the two most prevalent
methods of creating and manipulating strings in C++.<br>
</page>
</section>
<section type=Body name=Default title="7.2 const (Constant) Objects and const Member Functions">
<page>
<font size=18 bold>7.2 <b>const</b> (Constant) Objects and <b>const</b> Member Functions</font><hr>
<a href="^Engineer::c:s0p0"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>We have emphasized the <i>principle of least privilege </i>as
one of the most fundamental principles of good
software engineering. Let us see how this principle
applies to objects.<br>
<spacer width=16 height=1> <a href="^Engineer::c:s0p1"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>Some objects need to be modifiable and some do not.
The programmer may use the keyword <b>const</b> to specify
that an object is not modifiable, and that any attempt to
modify <a href="^Perform::c:s0p0"> <img src="bckgrnds/icons/perf_ico.gif" align=sidebar></a>the object is a syntax error. For example,<br>
<font size=2><br></font><font size=11><pre>
const Time noon( 12, 0, 0 );<p>
</pre></font>
</page>
<page>
declares a <b>const</b> object <b>noon</b> of class <b>Time</b> and
initializes it to 12 noon.<br>
<spacer width=16 height=1>C++ <a href="^Engineer::c:s0p2"> <img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>compilers disallow any member function calls for
<b>const</b> objects unless the member functions themselves
are also declared <b>const</b>. This is true even for <i>get</i>
member functions that do not modify the object.
Member functions <a href="^Errors::c:s0p0"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>declared <b>const</b> cannot modify the
<spacer width=16 height=1>A function is specified as <b>const</b> <i>both</i> in its prototype
and <a href="^Errors::c:s0p2"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>in its definition by inserting the keyword <b>const</b>
after the function's parameter list, and, in the case of
the function definition, before the left brace that begins <br>
</page>
<page>
the function body. For example, the following member
function of class <b>A
</b><br>
<font size=2><br></font><font size=11><pre>
int A::getValue() const { return privateDataMember };<p>
</pre></font>
simply returns the value of one of the object's data
members, and is appropriately declared <b>const</b>. <br>
<spacer width=16 height=1>An interesting problem arises here for constructors and
destructors, each of which often needs to <a href="^Errors::c:s0p3"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>modify
objects. The <b>const</b> declaration is not required for
constructors and destructors of <b>const</b> objects. A
constructor must be allowed to modify an object so that
the object can be initialized properly. A destructor must <br>
</page>
<page>
be able to perform its termination housekeeping chores
before an object is destroyed.<br>
<spacer width=16 height=1>The program of <a href="^Code::c:s0p0"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.1</a> instantiates two <b>Time</b>
objects--one <a href="^Practice::c:s0p0"><img src="bckgrnds/icons/gpp_ico.gif" align=sidebar></a>non-<b>const</b> object and one <tt><b>const</b></tt> object.
The program attempts to modify the <tt><b>const</b></tt> object <b>noon</b>
with non-<b>const</b> member functions <b>setHour</b> (at line 100)
and <b>printStandard</b> (at line 106). The program also
illustrates the three other combinations of member
function calls on objects--a non-<b>const</b> member
function on a non-<b>const</b> object (line 98), a <tt><b>const</b></tt>
member function on a non-<b>const</b> object (line 102) and a
<b>const</b> member function on a <b>const</b> object (line 104 and
105). The messages generated by one popular compiler <br>
</page>
<page>
for non-<b>const</b> member functions called on a <b>const</b>
object are shown in the output window. <br>
<spacer width=16 height=1>Notice that even though a constructor must be a non-
<b>const</b> member function, it can still be called for a <b>const</b>
object. The definition of the <b>Time</b> constructor at lines
39 and 40 <br>
<font size=2><br></font><font size=11><pre>
Time::Time( int hr, int min, int sec ) <p>
{ setTime( hr, min, sec ); }<p>
</pre></font>
shows that the <b>Time</b> constructor calls another non-
<b>const</b> member function--<b>setTime</b>--to <a href="^Engineer::c:s0p7"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>perform the
initialization of a <b>Time</b> object. Invoking a non-<b>const</b>
member function from the constructor call for a <tt><b>const</b></tt>
object is allowed.<br>
</page>
<page>
Also notice that line 106 (line 21 in the source file)<br>
<font size=2><br></font><font size=11><pre>
noon.printStandard(); // non-const const<p>
</pre></font>
generates a compiler error even though member
function <b>printStandard</b> of class <b>Time</b> does not modify
the object on which it is invoked.<br>
<spacer width=16 height=1> <a href="^Code::c:s0p1"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figure 7.2</a> demonstrates the use of a member initializer
to initialize <b>const</b> data member <b>increment</b> of class
<b>Increment.</b> The constructor for <b>Increment</b> is modified
as follows:<br>
<font size=2><br></font><font size=11><pre>
Increment::Increment( int c, int i )<p>
: increment( i )<p>
{ count = c; }<p>
</pre></font>
</page>
<page>
The notation <b>: increment( i )</b> initializes <b>increment</b> to
the value <b>i</b>. If multiple member initializers are needed,
simply include them in a comma-separated list after the
colon. <a href="^Debug::c:s0p0"><img src="bckgrnds/icons/dbt_ico.gif" align=sidebar></a>All data members <i>can</i> be initialized using
member <a href="^Engineer::c:s0p6"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>initializer syntax, but <b>const</b>s and references
<i>must</i> be <a href="^Errors::c:s0p4"> <img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>initialized in this manner. Later in this chapter,
we will see that member objects must be initialized this
way. In Chapter 9 when we study inheritance, we will
see that base class portions of derived classes also must
be initialized this way.<br>
<spacer width=16 height=1> <a href="^Code::c:s0p2"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figure 7.3</a> illustrates the compiler errors issued by one
popular C++ compiler for a program that attempts to <br>
</page>
<page>
initialize <b>increment</b> with an assignment statement
rather than with a member initializer.<br>
Note that the <b>print</b> function at line 24 is declared <b>const</b>.
It is <a href="^Engineer::c:s0p9"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>reasonable, yet strange, to label this function <b>const</b>
because we will probably never have a <b>const
Increment</b> object. <br>
<spacer width=16 height=1>C++ provides a new keyword called <tt><i><b>mutable</b></i></tt> that
affects the treatment <a href="^Debug::c:s0p1"><img src="bckgrnds/icons/dbt_ico.gif" align=sidebar></a>of <b>const</b> objects in a program. We
discuss keyword <b>mutable</b> in Chapter 21.<br>
</page>
<page>
<b>Select the true statement(s). </b><br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. An object can be declared const.">
<component type=button name=b label="Check Your Answer" width=125 height=24>
</page>
</section>
<section type=Body name=Default title="7.3 Composition: Objects as Members of Classes">
<page>
<font size=18 bold>7.3 Composition: Objects as Members of
Classes</font><hr>
An <b>AlarmClock</b> class object needs to know when it is
supposed to sound its alarm, so why not include a <b>Time</b>
object as a member of the <b>AlarmClock object</b>? Such a
capability is <a href="^Engineer::c:s0p11"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>called <i>composition</i>. A class can have
objects of other classes as members.<br>
<spacer width=16 height=1>When an object is created, its constructor is called
automatically, so we need to specify how arguments are
passed to member-object constructors. Member objects
are constructed in the order in which they are declared
(not in the order they are listed in the constructor's <br>
</page>
<page>
member initializer list) and before their enclosing class
objects (sometimes called <i>host objects</i>) are constructed.<br>
<spacer width=16 height=1> <a href="^Code::c:s0p3"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figure 7.4</a> uses class <b>Employee</b> and class <b>Date</b> to
demonstrate objects as members of other objects. Class
<b>Employee</b> contains <b>private </b>data members <b>firstName</b>,
l<b>astName</b>, <b>birthDate</b>, and <b>hireDate</b>. Members
<b>birthDate</b> and <b>hireDate </b>are <b>const</b> objects of class <b>Date</b>
which contains <b>private</b> data members <b>month</b>, <b>day</b> and
<b>year</b>. The program instantiates an <b>Employee</b> object,
and initializes and displays its data members. Note the
syntax of the function header in the <b>Employee</b>
constructor definition:<br>
</page>
<page>
<font size=2><br></font><font size=11><pre>
Employee::Employee( char *fname, char *lname,<p>
int bmonth, int bday, int byear,<p>
int hmonth, int hday, int hyear )<p>
: birthDate( bmonth, bday, byear ), <p>
hireDate( hmonth, hday, hyear )<p>
</pre></font>
The constructor takes eight arguments (<b>fname</b>, <b>lname</b>,
<b>bmonth</b>, <b>bday</b>, <b>byear</b>, <b>hmonth</b>, <b>hday</b>, and <b>hyear</b>). The
colon (<b>:</b>) in the header separates the member initializers
from the parameter list. The member initializers specify
the <b>Employee</b> arguments being passed to the
constructors of the member objects. Arguments
<b>bmonth</b>, <b>bday</b>, and <b>byear</b> are passed to the <b>birthDate</b>
constructor, and arguments <b>hmonth</b>, <b>hday</b>, and <b>hyear</b> <br>
</page>
<page>
are passed to the <b>hireDate</b> constructor. Multiple
member initializers are separated by commas. <br>
<spacer width=16 height=1>Remember that <tt><b>const</b></tt> members and references are also
initialized in the member initializer list (in Chapter 9,
we will see that base class portions of derived classes
are also initialized this way). Class <b>Date</b> and class
<b>Employee</b> each include a destructor function that prints
a message when a <b>Date</b> object or an <b>Employee</b> object is
destroyed, respectively. This enables us to confirm in
the program output that objects are constructed from the
inside out and destructed in the reverse order from the
outside in (i.e., the <b>Date</b> member objects are destroyed
after the <b>Employee</b> object that contains them). <br>
</page>
<page>
A member object does not need to be initialized
explicitly through a <a href="^Perform::c:s0p2"><img src="bckgrnds/icons/perf_ico.gif" align=sidebar></a>member initializer. If a member
initializer is not provided, the member <a href="^Errors::c:s0p5"> <img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>object's default
constructor will be called implicitly. Values, if any,
established by the default <a href="^Engineer::c:s0p12"> <img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>constructor can be
overridden by <i>set</i> functions.<br>
<spacer width=16 height=1>Notice the call to <b>Date</b> member function <b>print</b> at line
43. Many member functions of classes in C++ require
no arguments. This is because each member function
contains an implicit handle (in the form of a pointer) to
the object on which it operates. We discuss the implicit
In this first version of our <b>Employee</b> class (for ease of
programming), we use two 25-character arrays to
represent the first and last name of the <b>Employee</b>.
These arrays may be a waste of space for names shorter
than 24 characters (remember one character in each
array is for the terminating null character, <b>'\\0'</b>, of the
string). Also, names longer than 24 characters must be
truncated to fit into these character arrays. Later in this
chapter we will present another version of class
<b>Employee</b> that dynamically creates the exact amount of
space to hold the first and the last name. Also, we could
use two <b>string</b> objects to represent the names. Standard
library class <tt><b>string</b></tt> is presented in detail in Chapter 19.<br>
</page>
<page>
<b>Select the true statement(s). </b><br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. A class can have objects of other classes as members. This is known as composition.">
A class cannot have objects of other classes as members. <br>
mechanical example is shown here of how a <b>friend</b>
function works. Later in the book, <b>friend</b> functions are
used to overload operators for use with class objects
and to create iterator classes. Objects of an iterator class
are used to successively select items or perform an <br>
</page>
<page>
operation on items in a container class (see <a href="#s9p0">Section 7.9</a>)
object. Objects of container classes are capable of
storing items. Using <b>friends</b> is often appropriate when a
member function cannot be used for certain operations
as we will see in Chapter 8, "Operator Overloading."<br>
<spacer width=16 height=1>To declare a function as a <b>friend</b> of a class, precede the
function prototype in the class definition with the
keyword <b>friend</b>. <a href="^Practice::c:s0p1"><img src="bckgrnds/icons/gpp_ico.gif" align=sidebar></a>To declare class <b>ClassTwo</b> as a
<b>friend </b>of class <b>ClassOne</b> place a declaration of the
form<br>
<font size=2><br></font><font size=11><pre>
friend class ClassTwo;<p>
</pre></font>
in the definition of class <b>ClassOne</b>.<br>
</page>
<page>
Friendship is granted, not taken, i.e., for class B to be a
<b>friend</b> of class A, class A must explicitly declare that
class B is its <b>friend</b>. Also, friendship is neither
symmetric nor transitive, i.e., if class A is a <b>friend</b> of
class B, and class B is a <b>friend</b> of class C, you cannot
infer that class B is a <b>friend</b> of class A (again,
friendship is not symmetric), that class C is a <b>friend</b> of
class B, or that class A is a <b>friend</b> of class C (again,
friendship is not transitive). <br>
<spacer width=16 height=1> <a href="^Code::c:s0p4"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figure 7.5</a> demonstrates the declaration and use of
<tt><b>friend</b></tt> function <b>setX</b> for setting the <b>private</b> data
member <b>x </b>of class <b>count</b>. Note that the <b>friend</b>
declaration appears first (by convention) in the class <br>
</page>
<page>
declaration, even before <b>public</b> member functions are
declared. The program of <a href="^Code::c:s0p5"> <img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.6</a> demonstrates the
messages produced by the compiler when non-<b>friend</b>
function <b>cannotSetX</b> is called to modify <b>private</b> data
member <b>x</b>. <a href="^Code::c:s0p4"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figures 7.5</a> and <a href="^Code::c:s0p5"> <img src="bckgrnds/icons/code_ico.gif" align=sidebar>7.6</a> are intended to
introduce the "mechanics" of using <b>friend</b> functions--
practical examples of using <b>friend</b> functions appear in
forthcoming chapters.<br>
<spacer width=16 height=1>Note that function <b>setX</b> (line 17) is a C-style, stand-
alone function--it is not a member function of class
<b>Count</b>. For this reason, when <b>setX</b> is invoked for object
<b>counter</b> we use the statement at line 29<br>
<font size=2><br></font><font size=11><pre>
setX( counter, 8 ); // set x with a friend<p>
</pre></font>
</page>
<page>
that takes <b>counter</b> as an <a href="^Engineer::c:s0p16"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>argument rather than using a
handle (such as the name of the object) to call the
function as in<br>
<font size=2><br></font><font size=11><pre>
counter.setX( 8 );<p>
</pre></font>
It is possible to specify overloaded functions as <b>friend</b>s
of a class. Each overloaded function intended to be a
<b>friend</b> must be explicitly declared in the class definition
A function or class may be designated a friend of another class. <br>
<component type=button name=b label="Check Your Answer" width=125 height=24>
</page>
</section>
<section type=Body name=Default title="7.5 Using the this Pointer">
<page>
<font size=18 bold>7.5 Using the <b>this</b> Pointer</font><hr>
Every object has access to its own address through a
pointer called <b>this</b>. An object's <b>this</b> pointer is not part
of the object itself--i.e., the <b>this</b> pointer is not reflected
in the result of a <tt><b>sizeof</b></tt> operation on the object. Rather,
the <b>this</b> pointer is passed into the object (by the
compiler) as an implicit first argument on every non-
<b>static</b> member function call to the object (<b>static</b>
members are discussed in <a href="#s7p0">Section 7.7</a>).<br>
<spacer width=16 height=1>The <b>this</b> pointer is implicitly used to reference both the
data members and member functions of an object; it can
also be used explicitly. The type of the <b>this</b> pointer <br>
</page>
<page>
depends on the type of the object and whether the
member function in which <b>this</b> is used is declared
<b>const</b>. In a non-constant member function of class
<b>Employee</b>, the <b>this</b> <a href="^Perform::c:s0p4"><img src="bckgrnds/icons/perf_ico.gif" align=sidebar></a>pointer has type <b>Employee * const
</b>(a constant pointer to an <b>Employee</b> object). In a
constant member function of class <b>Employee</b>, the <b>this</b>
pointer has type <b>const Employee * const</b> (a constant
pointer to an <b>Employee</b> object that is constant).<br>
<spacer width=16 height=1>For now, we show a simple example of using the <b>this</b>
pointer explicitly; later in this chapter and in Chapter 8,
we show some substantial and subtle examples of using
<b>this</b>. Every non-<b>static</b> member function has access to <br>
</page>
<page>
the <b>this</b> pointer to the object for which the member is
being invoked. <br>
<spacer width=16 height=1> <a href="^Code::c:s0p6"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Figure 7.7</a> demonstrates the explicit use of the <b>this</b>
pointer to enable a member function of class <b>Test</b> to
print the <b>private</b> data <b>x</b> of a <b>Test</b> object. <br>
<spacer width=16 height=1>For illustration purposes, the <b>print</b> member function in
<a href="^Code::c:s0p6"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.7</a> first prints <b>x</b> directly. Then, <b>print</b> uses two
different notations for accessing <b>x</b> through the <b>this</b>
pointer--the arrow operator (<b>-></b>) off the <b>this</b> pointer and
the dot operator (<b>.</b>) off the dereferenced <b>this</b> pointer.<br>
<spacer width=16 height=1>Note the parentheses around <b>*this</b> when used with the
dot member selection operator (<b>.</b>). The parentheses are
needed because the dot operator has higher precedence <br>
</page>
<page>
than the <b>*</b> operator. Without the parentheses, the
expression <br>
<font size=2><br></font><font size=11><pre>
*this.x<p>
</pre></font>
would be evaluated as if it were parenthesized as
follows:<br>
<font size=2><br></font><font size=11><pre>
*( this.x )<p>
</pre></font>
which is a <a href="^Errors::c:s0p6"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>syntax error because the dot operator cannot
be used with a pointer. <br>
<spacer width=16 height=1>One interesting use of the <b>this</b> pointer is to prevent an
object from being assigned to itself. As we will see in
Every object has access to its own address through the this pointer. <br>
<component type=button name=b label="Check Your Answer" width=125 height=24>
</page>
</section>
<section type=Body name=Default title="7.6 Dynamic Memory Allocation with Operators new and delete">
<page>
<font size=18 bold>7.6 Dynamic Memory Allocation with Operators <b>new</b> and <b>delete
</b></font><hr>
The <b><i>new </i></b>and <b><i>delete</i></b> operators provide a nicer means of
performing dynamic memory allocation (for any built-
in or user-defined type) than with C's <b>malloc</b> and <b>free</b>
function calls. Consider the following code<br>
<font size=2><br></font><font size=11><pre>
TypeName *typeNamePtr;<p>
</pre></font>
In ANSI C, to dynamically create an object of type
<b>TypeName</b>, you would say<br>
<font size=2><br></font><font size=11><pre>
typeNamePtr = malloc( sizeof( TypeName ) );<p>
</pre></font>
</page>
<page>
This requires a function call to <b>malloc</b> and explicit use
of the <b>sizeof</b> operator. In versions of C prior to ANSI C,
you would also have to cast the pointer returned by
<b>malloc</b> with the cast <b>(TypeName *)</b>. Function <b>malloc</b>
does not provide any method of initializing the
allocated block of memory. In C++, you simply write<br>
<font size=2><br></font><font size=11><pre>
typeNamePtr = new TypeName;<p>
</pre></font>
The <b>new</b> operator automatically creates an object of the
proper size, calls the constructor for the object and
returns a pointer of the correct type. If new is unable to
find space, it returns a <b>0</b> pointer in versions of C++
prior to the ANSI/ISO draft standard. [Note: In Chapter
13, we will show you how to deal with <b>new</b> failures in <br>
</page>
<page>
the context of the ANSI/ISO C++ draft standard. In
particular, we will show how <tt><b>new</b></tt> "throws" an
"exception" and we will show how to "catch" that
exception and deal with it.] To free the space for this
object in C++ you must use the <b>delete</b> operator as
follows:<br>
<font size=2><br></font><font size=11><pre>
delete typeNamePtr;<p>
</pre></font>
C++ allows you to provide an <i>initializer</i> for a newly
created object as in:<br>
<font size=2><br></font><font size=11><pre>
float *thingPtr = new float ( 3.14159 ); <p>
</pre></font>
which initializes a newly created <b>float</b> object to
<b>3.14159</b>.<br>
</page>
<page>
A 10-element integer array can be created and assigned
to <b>arrayPtr</b> as follows:<br>
<font size=2><br></font><font size=11><pre>
int *arrayPtr = new int[ 10 ];<p>
</pre></font>
This array can be deleted with the statement<br>
<font size=2><br></font><font size=11><pre>
delete [] arrayPtr;<p>
</pre></font>
As we will see, <a href="^Errors::c:s0p7"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>using <b>new</b> and <b>delete</b> instead of <b>malloc
</b>and <b>free</b> offers other benefits as well. In particular, <b>new</b>
automatically <a href="^Errors::c:s0p9"> <img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>invokes the constructor, and <b>delete</b>
automatically <a href="^Practice::c:s0p2"> <img src="bckgrnds/icons/gpp_ico.gif" align=sidebar></a>invokes the class's destructor.<br>
Operator new automatically creates an object of the proper size, calls the constructor, and returns a pointer of the proper type. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. 0 is returned.">
If new cannot allocate the space for an object, -1 is returned. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. Operator delete is used to deallocate the memory allocated by new.">
Operator free is used to deallocate memory allocated by new. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. delete does automatically invoke the destructor for an object.">
delete does not automatically invoke the destructor for an object. <br>
<component type=button name=b label="Check Your Answer" width=125 height=24>
</page>
</section>
<section type=Body name=Default title="7.7 static Class Members">
<page>
<font size=18 bold>7.7 <b>static</b> Class Members</font><hr>
Each object of a class has its own copy of all the data
members of the class. In certain cases only one copy of
a variable should be shared by all objects of a class. A
<tt><b>static</b></tt> class variable is used for these and other reasons.
A <b>static</b> class variable represents "class-wide"
information. The declaration of a <b>static</b> member begins
with the keyword <b>static</b>.<br>
<spacer width=16 height=1>Let us motivate the need for <b>static</b> class-wide data with
a video game example. Suppose we have a video game
with <b>Martian</b>s and other space creatures. Each
<b>Martian</b> tends to be brave and willing to attack other <br>
</page>
<page>
space creatures when the <b>Martian</b> is aware that there
are at least 5 <b>Martian</b>s present. If there are fewer than
five <b>Martian</b>s present, each <b>Martian</b> becomes
cowardly. So each <b>Martian</b> needs to know the
<b>martianCount</b>. We could endow class <b>Martian</b> with
<b>martianCount </b>as a data member. If we do this, then
every <b>Martian</b> will have a separate copy of the data
member and every time we create a new <b>Martian</b> we
will have to update the data member <b>martianCount</b> in
every <b>Martian</b>. This wastes space with the redundant
copies and wastes time in updating the separate copies.
Instead, we declare <b>martianCount</b> to be <b>static</b>. This
makes <b>martianCount</b> class-wide data. Every <b>Martian</b> <br>
</page>
<page>
can see the <b>martianCount</b> as if it were a data member
of the <b>Martian</b>, but only one copy of the static
<b>martianCount</b> is maintained by C++. This saves space.
We save time by having the <b>Martian</b> constructor
increment the static <b>martianCount</b>. Because there is
only one copy, we do not have to increment separate
copies of <b>martianCount</b> for each <b>Martian</b> object.<br>
<spacer width=16 height=1>Although <b>static</b> <a href="^Perform::c:s0p6"><img src="bckgrnds/icons/perf_ico.gif" align=sidebar></a>data members may seem like global
variables, <b>static </b>data members have class scope. <b>static</b>
members can be <b>public</b>, <b>private</b> or <b>protected</b>. <b>static</b>
data members <i>must</i> be initialized <i>once</i> (and only once)
at file scope. A class's <b>public static</b> class members can
be accessed through any object of that class, or they can <br>
</page>
<page>
be accessed through the class name using the binary
scope resolution operator. A class's <b>private </b>and
<b>protected static</b> members must be accessed through
<b>public</b> member functions of the class or through
<b>friends</b> of the class. A class's <tt><b>static</b></tt> members exist
even when no objects of that class exist. To access a
<tt><b>public static</b></tt> class member when no objects of the class
exist, simply prefix the class name and the binary scope
resolution operator (<tt><b>::</b></tt>) to the name of the data member.
To access a <b>private</b> or <b>protected static</b> class member
when no objects of the class exist, a <b>public static</b>
member function must be provided and the function <br>
</page>
<page>
must be called by prefixing its name with the class
name and binary scope resolution operator.<br>
<spacer width=16 height=1>The program of <a href="^Code::c:s0p8"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.9</a> demonstrates the use of a
<tt><b>private static </b></tt>data member and a <tt><b>public static</b></tt> member
function. The data<a href="^Errors::c:s0p11"> <img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>member count is initialized to zero
at file scope with the statement<br>
<font size=2><br></font><font size=11><pre>
int Employee::count = 0;<p>
</pre></font>
Data member <b>count</b> maintains a count of the number of
objects of class <b>Employee</b> that have been instantiated.
When objects of class <b>Employee</b> exist, member <b>count</b>
can be referenced through any member function of an
<b>Employee</b> object--in this example, <b>count</b> is referenced
by both the constructor and the destructor. <br>
</page>
<page>
When no objects of class <b>Employee</b> exist, member
<b>count</b> can still be referenced, but only through a call to
<tt><b>static</b></tt> member function <b>getCount</b> as follows:<br>
<font size=2><br></font><font size=11><pre>
Employee::getCount()<p>
</pre></font>
In this example, function <b>getCount</b> is used to determine
the number of <b>Employee</b> objects currently instantiated.
Note<a href="^Engineer::c:s0p18"> <img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>that when there are no objects instantiated in the
program, the <b>Employee::getCount()</b> function call is
issued. However, when there are objects instantiated
function <b>getCount</b> can be called through one of the
objects as shown in the statement at lines 98 and 99<br>
</page>
<page>
<font size=2><br></font><font size=11><pre>
cout << "Number of employees after instantiation is "<p>
<< e1Ptr->getCount();<p>
</pre></font>
Note that the calls <b>e2Ptr->getCount()</b> and
<b>Employee::getCount()</b> would work in the preceding
statement as well.<br>
<spacer width=16 height=1>A member function may be declared <b>static</b> if it does not
access <a href="^Engineer::c:s0p19"><img src="bckgrnds/icons/seo_ico.gif" align=sidebar></a>non-<b>static</b> class data members and member
functions. Unlike non-<b>static </b>member functions, a <b>static</b>
member function has no <b>this</b> <a href="^Errors::c:s0p12"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>pointer because <b>static</b> data
members and <b>static</b> <a href="^Errors::c:s0p13"><img src="bckgrnds/icons/cpe_ico.gif" align=sidebar></a>member functions exist
independent of any objects of a class.<br>
</page>
<page>
Lines 94 and 95 use operator <b>new</b> to dynamically
allocate two <b>Employee</b> objects. When each <b>Employee</b>
object is allocated, its constructor is called. When
<b>delete</b> is used at lines 107 and 109 to deallocate the two
<b>Employee</b> objects, their <a href="^Practice::c:s0p3"><img src="bckgrnds/icons/gpp_ico.gif" align=sidebar></a>destructors are called.<br>
<spacer width=16 height=1>Note the use of <b><i>assert </i></b>in the <b>Employee</b> constructor
function. The <b>assert</b> "macro"--defined in the <b>assert.h</b>
header file--tests the value of a condition. If the value
of the expression is <b>false</b>, then <b>assert</b> issues an error
message and calls function <b><i>abort</i></b> (of the general utilities
header file--<b>stdlib.h</b>) to terminate program execution.
This is a useful debugging tool for testing if a variable
has a correct value. In this program, <b>assert</b> determines <br>
</page>
<page>
if the <b>new</b> operator was able to fulfill the request for
memory to be allocated dynamically. For example, in
the <b>Employee</b> constructor function, the following line
(which is also called an <b>assertion</b>)<br>
<font size=2><br></font><font size=11><pre>
assert( firstName != 0 );<p>
</pre></font>
tests pointer <b>firstName</b> to determine if it is not equal to
<b>0</b>. If the condition in the preceding assertion is <b>true</b>, the
program continues without interruption. If the condition
in the preceding assertion is <b>false</b>, an error message
containing the line number, the condition being tested,
and the file name in which the assertion appears is
printed, and the program terminates. The programmer
may then concentrate on this area of the code to find the <br>
</page>
<page>
error. In Chapter 13, "Exception Handling," we will
provide a better method of dealing with execution time
errors.<br>
<spacer width=16 height=1>Assertions do not have to be removed from the program
when debugging is completed. When assertions are no
longer needed for debugging purposes in a program, the
line<br>
<font size=2><br></font><font size=11><pre>
#define NDEBUG<p>
</pre></font>
is inserted at the beginning of the program file. This
causes the preprocessor to ignore all assertions instead
of the programmer having to delete each assertion
manually.<br>
</page>
<page>
Note that the implementations of functions
<b>getFirstName </b>and <b>getLastName</b> return to the client of
the class constant character pointers. In this
implementation, if the client wishes to retain a copy of
the first name or last name, the client is responsible for
copying the dynamically allocated memory in the
<b>Employee</b> object after obtaining the constant character
pointer from the object. Note that it is also possible to
implement <b>getFirstName</b> and <b>getLastName</b> so the
client is required to pass a character array and the size
of the array to each function. Then, the functions could
copy the first or last name into the character array
static members can be designated public, protected, or private. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. A class's static members exist from the beginning of program execution. ">
A class's static members only exist when an object of the class exists. <br>
<component type=button name=b label="Check Your Answer" width=125 height=24>
</page>
</section>
<section type=Body name=Default title="7.8 Data Abstraction and Information Hiding">
<page>
<font size=18 bold>7.8 Data Abstraction and Information Hiding</font><hr>
Classes normally hide their implementation details
from the clients of the classes. This is called
information hiding. As an example of information
hiding, let us consider a data structure called a <i>stack</i>. <br>
<spacer width=16 height=1>Think of a stack in terms of a pile of dishes. When a
dish is placed on the pile, it is always placed at the top
(referred to as <i>pushing onto the stack</i>), and when a dish
is removed from the pile, it is always removed from the
top (referred to as <i>popping off the stack</i>). Stacks are
known as <i>last-in, first-out (LIFO) data structures</i>--the <br>
</page>
<page>
last item pushed (inserted) on the stack is the first item
popped (removed) from the stack. <br>
<spacer width=16 height=1>The programmer may create a stack class and hide from
its clients the implementation of the stack. Stacks can
easily be implemented with arrays (or linked lists; see
Chapter 15, "Data Structures"). A client of a stack class
need not know how the stack is implemented. The
client simply requires that when data items are placed in
the stack, the data items will be recalled in last-in, first-
out order. Describing the functionality of a class
independent of its implementation is called <i>data
abstraction and C++ classes define so-called abstract
data types (ADTs)</i>. Although users may happen to know <br>
</page>
<page>
the details of how a class is implemented, users should
not write code that depends on these details. This means
that the implementation of a particular class (such as
one that implements a stack and its operations of <i>push
and pop</i>) can be altered or replaced without affecting
the rest of the system, as long as the <b>public</b> interface to
that class does not change. <br>
<spacer width=16 height=1>The job of a high-level language is to create a view
convenient for programmers to use. There is no single
accepted standard view--that is one reason why there
are so many programming languages. Object-oriented
programming in C++ presents yet another view.<br>
</page>
<page>
Most programming languages emphasize actions. In
these languages, data exists in support of the actions
programs need to take. Data is viewed as being "less
interesting" than actions, anyway. Data is "crude."
There are only a few built-in data types, and it is
difficult for programmers to create their own new data
types.<br>
<spacer width=16 height=1>This view changes with C++ and the object-oriented
style of programming. C++ elevates the importance of
data. The primary activity in C++ is creating new data
types (i.e., classes) and expressing the interactions
among objects of those data types.<br>
</page>
<page>
To move in this direction, the programming-languages
community needed to formalize some notions about
data. The formalization we consider is the notion of
abstract data types (ADTs). ADTs receive as much
attention today as structured programming did over the
last two decades. ADTs do not replace structured
programming. Rather, they provide an additional
formalization that can further improve the program
development process.<br>
<spacer width=16 height=1>What is an abstract data type? Consider the built-in type
<b>int</b>. What comes to mind is the notion of an integer in
mathematics, but <b>int</b> on a computer is not precisely
what an integer is in mathematics. In particular, <br>
</page>
<page>
computer <b>int</b>s are normally quite limited in size. For
example, <b>int</b> on a 32-bit machine may be limited
approximately to the range 2 billion to +2 billion. If
the result of a calculation falls outside this range, an
"overflow" error occurs and the machine responds in
some machine-dependent manner, including the
possibility of "quietly" producing an incorrect result.
Mathematical integers do not have this problem. So the
notion of a computer <b>int</b> is really only an
approximation to the notion of a real-world integer. The
same is true with <b>float</b>. <br>
<spacer width=16 height=1>Even <b>char</b> is an approximation; <b>char</b> values are
normally 8-bit patterns of ones and zeros; these patterns <br>
</page>
<page>
look nothing like the characters they represent such as a
capital <b>Z</b>, a lowercase <b>z</b>, a dollar sign (<b>$</b>), a digit (<b>5</b>),
and so on. Values of type <b>char</b> on most computers are
quite limited compared to the range of real-world
characters. The 7-bit ASCII character set provides for
128 different character values. This is completely
inadequate for representing languages such as Japanese
and Chinese that require thousands of characters.<br>
<spacer width=16 height=1>The point is that even the built-in data types provided
with programming languages like C++ are really only
approximations or models of real-world concepts and
behaviors. We have taken <b>int</b> for granted until this
point, but now you have a new perspective to consider. <br>
</page>
<page>
Types like <b>int</b>, <b>float</b>, <b>char</b> and others are all examples
of abstract data types. They are essentially ways of
representing real-world notions to some satisfactory
level of precision within a computer system.<br>
<spacer width=16 height=1>An abstract data type actually captures two notions,
namely a <i>data representation</i> and the <i>operations</i> that
are allowed on that data. For example, the notion of <b>int</b>
Container classes are classes designed to hold collections of objects. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. An iterator is an object that is used to access elements of a container.">
An iterator is a repetition structure used to execute statements in a program multiple times. <br>
It is desirable to hide the implementation details of a
class to prevent access to proprietary information
(including <b>private</b> data) and proprietary program logic
in a class. Providing clients of your class with a <i>proxy
class</i> that knows only the <b>public</b> interface to your class
enables the clients to use your class's services without
giving the client access to your class's implementation
details. <br>
<spacer width=16 height=1>Implementing a proxy class requires several steps (<a href="^Code::c:s0p9"> <img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig.
7.10</a>). First, we create the class definition and
implementation files for the class whose <b>private</b> data <br>
</page>
<page>
we would like to hide. Our example class, which we
call <b>Implementation</b>, is shown in <a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a>, part 1. The
proxy class <b>Interface</b> is shown in <a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a>, parts 2 and
3, and the test program and output are shown in <a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig.
7.10</a>, part 4.<br>
<spacer width=16 height=1>Class <b>Implementation</b> ( <a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a>, part 1 of 4) provides
a single <b>private</b> data member called <b>value</b> (this is the
data we would like to hide from the client), a
constructor to initialize <b>value</b>, and functions <b>setValue</b>
and <b>getValue</b>. <br>
<spacer width=16 height=1>We create a proxy class definition with an identical
<b>public </b>interface to that of class <b>Implementation</b>. The
only <b>private</b> member of the proxy class is a pointer to <br>
</page>
<page>
an object of class <b>Implementation</b>. Using a pointer in
this manner allows us to hide the implementation
details of class <b>Implementation</b> from the client. <br>
<spacer width=16 height=1>Class <b>Interface</b> in part 2 of <a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a> is the proxy class
for class <tt><b>Implementation</b></tt>. Notice that the only
mention in class <tt><b>Interface </b></tt>of the proprietary class
<b>Implementation</b> is in the pointer declaration (line 23).
When a class definition (such as class <b>Interface</b>) uses
only a pointer to another class (such as to class
<b>Implementation</b>), the class header file for that other
class (which would ordinarily reveal the <b>private</b> data of
that class) is not required to be included with <b>#include</b>.
You can simply declare that other class as a data type <br>
</page>
<page>
with a <i>forward class declaration</i> (line 15) before the
type is used in the file.<br>
<spacer width=16 height=1>The implementation file containing the member
functions for proxy class <b>Interface</b> (<a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a>, part 3) is
the only file that includes the header file
<tt><b>implementation.h </b></tt>containing class <b>Implementation</b>
The file <b>interface.cpp</b> (<a href="^Code::c:s0p9"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a>, part 3) is provided to
the client as a precompiled object file along with the
header file <b>interface.h</b> that includes the function
prototypes of the services provided by the proxy class.
Because file <b>interface.cpp</b> is made available to the
client only as compiled object code, the client is not <br>
</page>
<page>
able to see the interactions between the proxy class and
the proprietary class.<br>
<spacer width=16 height=1>The program in part 4 of<a href="^Code::c:s0p9"> <img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.10</a> tests class <b>Interface</b>.
Notice that only the header file for class <b>Interface</b> is
included in <b>main</b>--there is no mention of the existence
of a separate class called <b>Implementation</b>. Thus, the
client never sees the <b>private data</b> of class
A Proxy class provides client code with access to the public services of another class without allowing the client to see the data representation of the other class. <br>
<component type="checkbox" width=20 height=18 label="" name="" feedback="False. C++ does not contain a proxy keyword. The programmer must follow several steps in order to create a proxy class.">
Proxy classes are created with the proxy keyword. <br>
a) ________ syntax is used to initialize constant members of a class.<br>
b) A nonmember function must be declared as a ________ of a class to have
access to that class's <b>private</b> data members.<br>
c) The ________ operator dynamically allocates memory for an object of a
specified type and returns a ________ to that type.<br>
d) A constant object must be ________; it cannot be modified after it is
created.<br>
e) A ________ data member represents class-wide information.<br>
f) An object's member functions have access to a "self pointer" to the object
called the ________ pointer.<br>
<foreign name="answers" url="^Answers::c:s0p0">
</page>
<page pagename="Exercise 7.1">
g) The keyword ________ specifies that an object or variable is not
modifiable after it is initialized.<br>
h) If a member initializer is not provided for a member object of a class, the
object's ________ is called.<br>
i) A member function can be declared <b>static</b> if it does not access ________
class members.<br>
j) Member objects are constructed ________ their enclosing class object.<br>
k) The ________ operator reclaims memory previously allocated by new.<br>
<foreign name="answers" url="^Answers::c:s0p0">
<br>
</page>
<page pagename="Exercise 7.2">
<b>Exercise 7.2</b><br>
Find the error(s) in each of the following and explain how to correct it.<br>
<font size=2><br></font><font size=11><pre>
a) class Example {<p>
public:<p>
Example( int y = 10 ) { data = y; }<p>
int getIncrementedData() const { return ++data; }<p>
static int getCount()<p>
{<p>
cout << "Data is " << data << endl;<p>
return count;<p>
}<p>
</pre></font>
<foreign name="answers" url="^Answers::c:s0p2">
</page>
<page pagename="Exercise 7.2">
<font size=2><br></font><font size=11><pre>
private:<p>
</pre></font>
<font size=2><br></font><font size=11><pre>
int data;<p>
static int count;<p>
};<p>
b) char *string;<p>
string = new char[ 20 ];<p>
free( string );<p>
</pre></font>
<foreign name="answers" url="^Answers::c:s0p2">
<br>
</page>
<page pagename="Exercise 7.3">
<b>Exercise 7.3</b><br>
Compare and contrast dynamic memory allocation with the C++ operators <b>new</b>
and <b>delete</b>, with dynamic memory allocation with the C Standard Library
functions <b>malloc</b> and <b>free</b>.<br>
<br>
</page>
<page pagename="Exercise 7.4">
<b>Exercise 7.4</b><br>
Explain the notion of friendship in C++. Explain the negative aspects of
friendship as described in the text.<br>
<br>
</page>
<page pagename="Exercise 7.5">
<b>Exercise 7.5</b><br>
Can a correct <b>Time</b> class definition include both of the following constructors?
If not, explain why not.<br>
<font size=2><br></font><font size=11><pre>
Time ( int h = 0, int m = 0, int s = 0 );<p>
Time();<p>
</pre></font>
<br>
</page>
<page pagename="Exercise 7.6">
<b>Exercise 7.6</b><br>
What happens when a return type, even <b>void</b>, is specified for a constructor or
destructor?<br>
<br>
</page>
<page pagename="Exercise 7.7">
<b>Exercise 7.7</b><br>
Create a <b>Date</b> class with the following capabilities:<br>
a) Output the date in multiple formats such as <br>
DDD YYYY<p>
MM/DD/YY<p>
June 14, 1992<br>
b) Use overloaded constructors to create <b>Date</b> objects initialized with dates of
the formats in part (a).<br>
c) Create a <b>Date</b> constructor that reads the system date using the standard
library functions of the <b>time.h</b> header and sets the <b>Date</b> members.<br>
In Chapter 8, we will be able to create operators for testing the equality of two
dates and for comparing dates to determine if one date is prior to, or after,
another.<br>
<foreign name="answers" url="^Answers::c:s0p4">
</page>
<page pagename="Exercise 7.8">
<b>Exercise 7.8</b><br>
Create a <b>SavingsAccount</b> class. Use a <b>static</b> data member to contain the
<b>annualInterestRate</b> for each of the savers. Each member of the class contains a
<b>private</b> data member <b>savingsBalance</b> indicating the amount the saver currently
has on deposit. Provide a <b>calculateMonthlyInterest</b> member function that
calculates the monthly interest by multiplying the <b>balance</b> by
<b>annualInterestRate</b> divided by 12; this interest should be added to
<b>savingsBalance</b>. Provide a <b>static</b> member function <b>modifyInterestRate</b> that
sets the <b>static</b> <b>annualInterestRate</b> to a new value. Write a driver program to
test class <b>SavingsAccount</b>. Instantiate two different <b>savingsAccount</b> objects,
<b>saver1</b> and <b>saver2</b>, with balances of $2000.00 and $3000.00, respectively. Set
<b>annualInterestRate</b> to 3%, then calculate the monthly interest and print the new<br>
<foreign name="answers" url="^Answers::c:s0p5">
</page>
<page pagename="Exercise 7.8">
balances for each of the savers. Then set the <b>annualInterestRate</b> to 4% and
calculate the next month's interest and print the new balances for each of the
savers.<br>
<foreign name="answers" url="^Answers::c:s0p5">
<br>
</page>
<page pagename="Exercise7.9">
<b>Exercise7.9</b><br>
Create a class called <b>IntegerSet</b>. Each object of class <b>IntegerSet</b> can hold
integers in the range 0 through 100. A set is represented internally as an array of
ones and zeros. Array element <b>a[ i ]</b> is 1 if integer <i>i</i> is in the set. Array element
<b>a[ j ]</b> is 0 if integer <i>j</i> is not in the set. The default constructor initializes a set to
the so-called "empty set," i.e., a set whose array representation contains all
zeros. <br>
Provide member functions for the common set operations. For example, provide
a <b>unionOfIntegerSets</b> member function that creates a third set which is the set-
theoretic union of two existing sets (i.e., an element of the third set's array is set
to 1 if that element is 1 in either or both of the existing sets, and an element of
the third set's array is set to 0 if that element is 0 in each of the existing sets).<br>
</page>
<page pagename="Exercise7.9">
Provide an <b>intersectionOfIntegerSets</b> member function that creates a third set
which is the set-theoretic intersection of two existing sets (i.e., an element of the
third set's array is set to 0 if that element is 0 in either or both of the existing
sets, and an element of the third set's array is set to 1 if that element is 1 in each
of the existing sets).<br>
Provide an <b>insertElement</b> member function that inserts a new integer <i>k</i> into a
set (by setting <b>a[k]</b> to 1). Provide a <b>deleteElement</b> member function that deletes
integer <i>m</i> (by setting <b>a[m]</b> to 0). <br>
Provide a <b>setPrint</b> member function that prints a set as a list of numbers
separated by spaces. Print only those elements that are present in the set (i.e.,
their position in the array has a value of 1). Print --- for an empty set.<br>
Provide an <b>isEqualTo</b> member function that determines if two sets are equal.<br>
</page>
<page pagename="Exercise7.9">
Provide an additional constructor to take five integer arguments which can be
used to initialize a set object. If you want to provide fewer than five elements in
the set, use default arguments of <p>
-1 for the others.<br>
Now write a driver program to test your <b>IntegerSet</b> class. Instantiate several
<b>IntegerSet</b> objects. Test that all your member functions work properly. <br>
<br>
</page>
<page pagename="Exercise 7.10">
<b>Exercise 7.10</b><br>
It would be perfectly reasonable for the <b>Time</b> class of <a href="^Code::c:s0p7"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.8</a> to represent the
time internally as the number of seconds since midnight rather than the three
integer values hour, <b>minute</b> and <b>second</b>. Clients could use the same <b>public</b>
methods and get the same results. Modify the <b>Time</b> class of <a href="^Code::c:s0p7"><img src="bckgrnds/icons/code_ico.gif" align=sidebar>Fig. 7.8</a> to
implement the <b>Time</b> as the number of seconds since midnight and show that
there is no visible change in functionality to the clients of the class.<br>